﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.BLL;
using ZF.BLL;
using System.Linq.Expressions;
using ZF.BLL;
using System.Linq.Expressions;
using GCELibrary.Current;
using ZF.BLL.Linq;
using GCELibrary.Current;
using System.Web.UI.HtmlControls;
using ZF.Model;
namespace ZF.WS.expert
{
    public partial class info : BLL.Page.PageBase
    {
        public Model.US_Member Expert { get; set; }
        public string EType
        {
            get
            {
                return DictionaryConfig.EExpertType.FirstOrDefault(p => p.Key == Expert.ExpertType).Text;
            }
        }
        [PageArgument(Key = "id", CanNull = false)]
        public int Id { get; set; }

        public static Random Random = new Random();
        protected void Page_Load(object sender, EventArgs e)
        {
            using (var dc = SiteInfo.CreateDBDataContext())
            {
                Expert = dc.US_Member.FirstOrDefault(p => p.MemberId == Id && p.IsExpert);

                if (Expert == null)
                {
                    throw WarnFactory.CreateWarn(WarnCode.ReocrdNoFind);
                }
                this.AirHtml1.Text = Expert.About;
                Expert.E_Article.Load();
                //this.lvArticle.DataSource = Expert.E_Article.Where(p => p.Type == 1).ToList();
                //this.lvArticle.DataBind();
                //this.lvArticle2.DataSource = Expert.E_Article.Where(p => p.Type == 2).ToList();
                //this.lvArticle2.DataBind();

       

                Dictionary<int, ArticleType[]> atsDic = new Dictionary<int, ArticleType[]>();

                atsDic[1] = new ArticleType[] { ArticleType.我的文章, ArticleType.学术研究, ArticleType.案例分析, };//风水师
                atsDic[2] = new ArticleType[] { ArticleType.我的文章, ArticleType.设计理念, ArticleType.设计案例, };//设计师
                atsDic[3] = new ArticleType[] { ArticleType.我的文章,   };//地产顾问
                atsDic[4] = new ArticleType[] { ArticleType.我的文章, ArticleType.合作银行, ArticleType.贷款种类, };//房货顾问

                var atIds = atsDic[Expert.ExpertType].Select(p => (int)p).ToArray();

                
                var artList=Expert.E_Article.Where(p => atIds.Contains(p.Type)).ToList();
                Dictionary<ArticleType,object> dicObj=new Dictionary<ArticleType,object>();


                var artGroup = atIds.Select(p => new
                {
                    Key = p.Convert<ArticleType>(),
                    Value = artList.Where(a => a.Type == p).Take(6).ToList()

                }).ToList();
                 
               this.lvArtList.DataSource = artGroup;
               this.lvArtList.DataBind();

               this.lvArtList1.DataSource = artGroup;
               this.lvArtList1.DataBind();















                var list = dc.H_Estate.Where(p => p.IsVerify).Where(p => p.MemberId == Id)
                   .OrderByDescending(p => p.EstateId).Take(10).ToList();


           
                var cz = dc.H_House.Where(p => p.Status == 1 && p.IsVerify).Where(p => p.DealType == 1 || p.DealType == 2)
                    .Where(p => p.MemberId == Id)
                           .OrderByDescending(p => p.HouseId).Take(6).ToList().Select(p =>
                               new
                               {
                                   Address = p.Address,
                                   House = p,
                                   City = SiteInfo.Instance.GetAreaOrDefault(p.AreaId1).Name,
                                   Model = string.Format("{0}房{0}厅", p.HX_Fan, p.HX_Tin),
                                   Price = p.Price,
                                   AddTime = p.AddTime,
                                   Area = DictionaryConfig.HArea.DefaultIfEmpty(a => p.AreaId2.HasValue && a.AreaId == p.AreaId2.Value, new ZF.Model.Dic_Area()).Name,
                               });

                var cs = dc.H_House.Where(p => p.Status == 1 && p.IsVerify).Where(p => p.DealType == 3 || p.DealType == 4)
               .Where(p => p.MemberId == Id)
                      .OrderByDescending(p => p.HouseId).Take(6).ToList().Select(p =>
                          new
                          {
                              Address = p.Address,
                              House = p,
                              City = SiteInfo.Instance.GetAreaOrDefault(p.AreaId1).Name,
                              Model = string.Format("{0}房{0}厅", p.HX_Fan, p.HX_Tin),
                              Price = p.Price,
                              AddTime = p.AddTime,
                              Area = DictionaryConfig.HArea.DefaultIfEmpty(a => p.AreaId2.HasValue && a.AreaId == p.AreaId2.Value, new ZF.Model.Dic_Area()).Name,
                          });
                this.lvJPLP.DataSource = cz;
                this.lvJPLP.DataBind();
                this.lvJPLP1.DataSource = cs;
                this.lvJPLP1.DataBind();
            }

        }
        protected override void OnPreRender(EventArgs e)
        {
           
            var key=Expert.ExpertType.ToString();
            foreach (Control c in  this.divContext.Controls)
            {
                if (c is HtmlControl)
                {
                    var hc = (HtmlControl)c;
                    if (!string.IsNullOrEmpty(hc.Attributes["key"]))
                    {
                        hc.Visible = hc.Attributes["key"].Split(',').Contains(key);
                    }
                }
            }



            base.OnPreRender(e);
        }
    }
}
